package practice;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: https://leetcode.cn/problems/two-sum/
 * @Author Ammar
 * @Create 2023/7/19 19:39
 */
public class _1_两数之和 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            Integer integer = map.get(nums[i]);
            if (integer == null) {
                map.put(target - nums[i], i);
                continue;
            }
            return new int[]{i, integer};
        }
        return null;
    }
}
